package com.example.yangbo.abc;

import android.graphics.drawable.AnimationDrawable;
import android.icu.util.Calendar;
import android.net.rtp.AudioGroup;
import android.os.Build;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Chronometer;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import java.util.LinkedList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements DatePicker.OnDateChangedListener {

    private TestListViewAdapter testListViewAdapter;
    private ListView listView;
    private List<TestListViewModel> dataSourceOfList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //listview
        setContentView(R.layout.activity_testlistview);
        listView = (ListView)findViewById(R.id.testlistview);

        dataSourceOfList = new LinkedList<TestListViewModel>();
        for (int i = 0; i < 5; i++) {
            TestListViewModel model0 = new TestListViewModel();
            model0.setContent("content"+i);
            model0.setTitle("title"+i);
            model0.setHeaderImgId(R.drawable.loading_01);
            dataSourceOfList.add(model0);
        }

        testListViewAdapter = new TestListViewAdapter();
        testListViewAdapter.setmContext(this);
        testListViewAdapter.setDataSourceOfList((LinkedList<TestListViewModel>) dataSourceOfList);

        TextView header = new TextView(this);
        header.setText("headr");

        TextView footer = new TextView(this);
        footer.setText("footer");

        listView.addHeaderView(header);
        listView.addFooterView(footer);

        listView.setAdapter(testListViewAdapter);




        //adapter
//        setContentView(R.layout.activity_adapter);
//        String[] strs = {"基神","B神","翔神","曹神","J神", "基神","B神","翔神","曹神","J神", "基神","B神","翔神","曹神","J神", "基神","B神","翔神","曹神","J神"};
//        ArrayAdapter<String> adapter = new ArrayAdapter<String>
//                (this,android.R.layout.simple_expandable_list_item_1,strs);
//        ListView list_test = (ListView) findViewById(R.id.list_test);
//        list_test.setAdapter(adapter);


        //time
//        setContentView(R.layout.activity_time);
//        Chronometer chronometer = (Chronometer)findViewById(R.id.chronometer);
//        chronometer.start();
//
//        DatePicker datePicker = (DatePicker)findViewById(R.id.datePicker);
//        Calendar calendar = Calendar.getInstance();
//        int year=calendar.get(Calendar.YEAR);
//        int monthOfYear=calendar.get(Calendar.MONTH);
//        int dayOfMonth=calendar.get(Calendar.DAY_OF_MONTH);
//        datePicker.init(year, monthOfYear, dayOfMonth, this);



        //scrollview
//        setContentView(R.layout.activity_scrollview);



        //progress
//        setContentView(R.layout.activity_progress);
//        final ImageView img_pgbar = (ImageView) findViewById(R.id.img_pgbar);
//        final AnimationDrawable ad = (AnimationDrawable)img_pgbar.getDrawable();
//        ad.start();
//        img_pgbar.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                ad.stop();
//            }
//        }, 10000);




        //button
//        setContentView(R.layout.activity_button);
//        final Button button0 = (Button)findViewById(R.id.btnOne);
//        final Button button1 = (Button)findViewById(R.id.btnTwo);
//        button1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (button1.getText().toString().equals("按钮不可用")) {
//                    button1.setText("按钮可用");
//                    button0.setEnabled(true);
//                } else {
//                    button1.setText("按钮不可用");
//                    button0.setEnabled(false);
//                }
//            }
//        });
//        RadioGroup audioG = (RadioGroup)findViewById(R.id.radioGroup);
//        audioG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
//                RadioButton rButton = (RadioButton)findViewById(i);
//                Log.i("nowSelectedSex", rButton.getText().toString());
//            }
//        });
//        final CheckBox checkBox = (CheckBox)findViewById(R.id.CheckBox1);
//        checkBox.setChecked(true);
//        checkBox.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (checkBox.isChecked()) {
//                    Log.i("是否同意：","同意了注册协议");
//                } else  {
//                    Log.i("是否同意：","未同意注册协议");
//                }
//            }
//        });
//        Button protocolB = (Button)findViewById(R.id.protocolButton);
//        protocolB.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Log.i("注意","点击了协议按钮");
//            }
//        });




        //textView
//        setContentView(R.layout.activity_textview);
//        TextView tx = (TextView)findViewById(R.id.txtOne);
//        String s1 = "<font color='blue'><b>百度一下，你就知道~：</b></font><br>";
//        s1 += "<a href = 'http://www.baidu.com'>百度</a>";
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//            tx.setText(Html.fromHtml(s1, Html.FROM_HTML_MODE_COMPACT));
//        } else {
//            tx.setText(Html.fromHtml(s1));
//        }
//        tx.setMovementMethod(LinkMovementMethod.getInstance());

    }

    @Override
    public void onDateChanged(DatePicker datePicker, int i, int i1, int i2) {

    }
}
